package com.example.service.impl;

import com.example.mapper.StudentMapper;
import com.example.params.StudentQueryParam;
import com.example.pojo.Student;
import com.example.service.StudentSevice;
import com.example.vo.student.GetAllStudentInfoVo;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

import org.apache.ibatis.annotations.Select;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;

@Service
public class StudentServiceImpl implements StudentSevice {
    @Autowired
    private StudentMapper studentMapper;
    public GetAllStudentInfoVo queryAllStudent(StudentQueryParam studentQueryParam) {
        PageHelper.startPage(studentQueryParam.getPage(),studentQueryParam.getPageSize());
        List<Student> students = studentMapper.queryAllStudent(studentQueryParam);
        Page<Student> studentPage = (Page<Student>) students;

        return new GetAllStudentInfoVo(studentPage.getTotal(),studentPage.getResult());
    }

    public boolean addStudent(Student student) {
        LocalDateTime now = LocalDateTime.now();
        student.setCreateTime(now);
        student.setUpdateTime(now);
        return studentMapper.addStudent(student)>0;
    }

    public Student getStudentById(Integer id) {
        return studentMapper.getStudentById(id);
    }

    public boolean updateStudent(Student student) {
        LocalDateTime now = LocalDateTime.now();
        student.setUpdateTime(now);
        return studentMapper.updateStudent(student)>0;
    }

    public boolean deleteStudentByIds(List<Integer> ids) {
        return studentMapper.deleteStudentByIds(ids)>0;
    }

    public boolean handleViolation(Integer id, Integer score) {
        return studentMapper.handleViolation(id,score)>0;
    }
}
